﻿
using System.ComponentModel;
namespace MyFloridaHouse.libSvDTO
{
	/// <summary>
	/// Criteria Dataset Membe rDTO, inherits INotifyPropertyChanged
	/// </summary>
    public class CriteriaDatasetMemberDTO : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged
		/// <summary>
		/// Occurs when a property value changes.
		/// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
		/// <summary>
		/// Notifies the property changed.
		/// </summary>
		/// <param name="propertyName">Name of the property.</param>
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

		/// <summary>
		/// local integer variable
		/// </summary>
        private int _dataDictionaryID;

		/// <summary>
		/// Gets or sets the data dictionary ID.
		/// </summary>
		/// <value>The data dictionary ID.</value>
        public int dataDictionaryID
        {
            get { return _dataDictionaryID; }
            set { if (_dataDictionaryID != value) { _dataDictionaryID = value; } }
        }

        private string _dataName = "not found";
		/// <summary>
		/// Gets or sets the name of the data.
		/// </summary>
		/// <value>The name of the data.</value>
        public string dataName
        {
            get { return _dataName; }
            set { if (_dataName != value) { _dataName = value; } }
        }

        private int _valueMin = 0;
		/// <summary>
		/// Gets or sets the value min.
		/// </summary>
		/// <value>The value min.</value>
        public int valueMin
        {
            get { return _valueMin; }
            set { if (_valueMin != value) { _valueMin = value; } }
        }

        private int _valueMax = 0;
		/// <summary>
		/// Gets or sets the value max.
		/// </summary>
		/// <value>The value max.</value>
        public int valueMax
        {
            get { return _valueMax; }
            set { if (_valueMax != value) { _valueMax = value; } }
        }

        private int _queryMin = 0;
		/// <summary>
		/// Gets or sets the query min.
		/// </summary>
		/// <value>The query min.</value>
        public int queryMin
        {
            get { return _queryMin; }
            set { if (_queryMin != value) { _queryMin = value; NotifyPropertyChanged("queryMin"); NotifyPropertyChanged("pctQueryMin"); } }
        }

        private int _queryMax = 0;
		/// <summary>
		/// Gets or sets the query max.
		/// </summary>
		/// <value>The query max.</value>
        public int queryMax
        {
            get { return _queryMax; }
            set { if (_queryMax != value) { _queryMax = value; NotifyPropertyChanged("queryMax"); NotifyPropertyChanged("pctQueryMax"); } }
        }


		/// <summary>
		/// Gets or sets the PCT query min.
		/// </summary>
		/// <value>The PCT query min.</value>
        public int pctQueryMin
        {
            get { return (int)((((double)queryMin - (double)offset) / ((double)range)) * 100.0); }
            set 
            { 
                if (pctQueryMin != value) 
                {
                    int val = (int) ((double)value / 100.0 * (double)range);
                    queryMin = (int) val + offset; 
                } 
            }

        }

		/// <summary>
		/// Gets or sets the PCT query max.
		/// </summary>
		/// <value>The PCT query max.</value>
        public int pctQueryMax
        {
            get { return (int) ( (( (double)queryMax - (double) offset) / ((double) range)) * 100.0); }
            set
            {
                if (pctQueryMax != value)
                {
                    int val = (int) ((double) value/100.0 * (double) range );
                    queryMax = val + offset;
                }
            }
        }



        private bool _isQueryCriteria = true;
		/// <summary>
		/// Gets or sets a value indicating whether this instance is query criteria.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is query criteria; otherwise, <c>false</c>.
		/// </value>
        public bool isQueryCriteria
        {
            get { return _isQueryCriteria; }
            set { if (_isQueryCriteria != value) { _isQueryCriteria = value; NotifyPropertyChanged("isQueryCriteria"); } }
        }

        private bool _isSelected = false;
		/// <summary>
		/// Gets or sets a value indicating whether this instance is selected.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is selected; otherwise, <c>false</c>.
		/// </value>
        public bool isSelected
        {
            get { return _isSelected; }
            set { if (_isSelected != value) { _isSelected = value; NotifyPropertyChanged("isSelected"); } }
        }

        #region computed values
		//Todo: pctValueMin is hard coded to return the value 0.
		/// <summary>
		/// Gets the PCT value min.
		/// </summary>
		/// <value>The PCT value min.</value>
        public int pctValueMin
        {
            get { return 0; }
        }

		//Todo: pctValueMax is hard coded to return the value 100.
		/// <summary>
		/// Gets the PCT value max. (alway returns 100)
		/// </summary>
		/// <value>The PCT value max.</value>
        public int pctValueMax
        {
            get { return 100; }
        }
		/// <summary>
		/// Gets the range.
		/// </summary>
		/// <value>The range.</value>
        public int range
        {
            get { return _valueMax - _valueMin; }
        }
		/// <summary>
		/// Gets the offset.
		/// </summary>
		/// <value>The offset.</value>
        public int offset
        {
            get { return _valueMin; }
        }
        #endregion

		/// <summary>
		/// Initializes a new instance of the <see cref="CriteriaDatasetMemberDTO"/> class.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <param name="isQueryCriteria">if set to <c>true</c> [is query criteria].</param>
		/// <param name="queryMin">The query min.</param>
		/// <param name="queryMax">The query max.</param>
        public CriteriaDatasetMemberDTO(int id, bool isQueryCriteria, int queryMin, int queryMax)
        {
            //Todo: There is no need for local variables the way this is coded.  These should be converted to locals if possible.
			//
			this.dataDictionaryID = id;
            this.isQueryCriteria = isQueryCriteria;
            this.queryMax = queryMax;
            this.queryMin = queryMin;
        }
    }

}
